package observerapplication;

import java.util.ArrayList;
import java.util.List;


// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
// #[regen=yes,id=DCE.8C9F6B4C-ACBB-4945-0AAE-ACD022768964]
// </editor-fold> 
public class Magatzem implements Subject {

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.8440EC52-E486-4AEC-BB54-38F4FC292A69]
    // </editor-fold> 
    private int stock;

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.EAB6C2AB-D51C-E0B1-6FFE-458EF5BFC1F9]
    // </editor-fold> 
    private List<Observer> observadors;

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.EF068513-E5C7-72B7-D092-75618729FFE2]
    // </editor-fold> 
    public Magatzem () {
        observadors = new ArrayList<Observer>();
        stock = 10;

    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.57B11205-01C2-67B5-C392-23061FA3292E]
    // </editor-fold> 
    public List<Observer> getObservadors () {
        return observadors;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.9D295CEE-6608-3BB2-D82C-6AF4AC59A769]
    // </editor-fold> 
    public void setObservadors (List<Observer> val) {
        this.observadors = val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.67F4176A-9F4B-BB6D-78A3-4F1E7DBFD90F]
    // </editor-fold> 
    public void add (Observer observer) {
        observadors.add(observer);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.C98001F0-837B-E3EB-D44F-D5B4EF441CD2]
    // </editor-fold> 
    public void remove (Observer observer) {
        observadors.remove(observer);
           }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.B0372439-E0B6-84DE-76D1-A0F1B5B77579]
    // </editor-fold> 
    public int getStock () {
        return stock;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.2D3E1860-68B1-5566-3B90-8562FE67DD29]
    // </editor-fold> 
    public void setStock (int val) {
        this.stock = val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.714249C5-F3DB-A789-E6A0-39371DE241B1]
    // </editor-fold> 
    public void decrementaStock () {
        this.stock--;
        if (stock == 4){
            for (Observer observer: observadors){
                observer.update();
            }
        }
    }
}

